<?php

class Player
{
    private $_piece = null;
    private $_balance = 0;
    private $_turns_played = 0;

    public function __construct($piece)
    {
        $piece->setPlayer($this);
        $this->setPiece($piece);
    }

    public function __toString()
    {
        return $this->getPiece()->getName();
    }

    public function setPiece($piece)
    {
        $this->_piece = $piece;
    }

    public function getPiece()
    {
        return $this->_piece;
    }

    public function setTurnsPlayed($turns_played)
    {
        $this->_turns_played = $turns_played;
    }

    public function getTurnsPlayed()
    {
        return $this->_turns_played;
    }

    public function setBalance($amount)
    {
        $this->_balance = $amount;
    }

    public function getBalance()
    {
        return $this->_balance;
    }

    public function deposit($amount)
    {
        $this->setBalance($this->getBalance() + $amount);
    }

    public function withdraw($amount)
    {
        $this->setBalance($this->getBalance() - $amount);
    }

    public function incrementTurnsPlayed()
    {
        $turns_played = $this->getTurnsPlayed();
        $this->setTurnsPlayed($turns_played + 1);
    }

    public function takeTurn($dice)
    {
        // do the turn
        $new_space = $this->getPiece()->move($dice->roll());

        // update turns played
        $this->incrementTurnsPlayed();
    }
}
